using Digitalmes.Application.Mes.Equipments.Alarms.Commands;
using Digitalmes.Application.Mes.Equipments.Alarms.Queries;

namespace Digitalmes.WebApi.Endpoints.Mes.Equipments;

/// <summary>
/// 设备警报记录终结点。
/// </summary>
public sealed class AlarmRecordEndpoint : EndpointGroupBase
{
    public override void Map(WebApplication app)
    {
        app.MapGroup(this, "mes/equipment", "alarmRecord")
            .RequireAuthorization()
            .MapGet(GetAlarmRecordPagedListAsync, "list-page")
            .MapPut(CloseAlarmRecordAsync, "close/{id}");
    }

    [EndpointDescription("分页查询设备警报记录")]
    public async Task<IApiResult> GetAlarmRecordPagedListAsync(ISender sender, [AsParameters] GetAlarmRecordListWithPagedQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("关闭设备警报记录")]
    public async Task<IApiResult> CloseAlarmRecordAsync(ISender sender, long id)
    {
        var result = await sender.Send(new CloseAlarmRecordCommand(id));
        return result.ToApiResult();
    }
}
